#!/usr/bin/python
# -*- coding: utf8 -*-

from serial import Serial as SPort
from threading import Thread as ThreadParent
from time import sleep

def getkey():
	import sys, tty, termios
	#~ fd = sys.stdin.fileno()
	#~ old_settings = termios.tcgetattr(fd)
	#~ tty.setraw(sys.stdin.fileno())
	return sys.stdin.read(1)

class StateMachine(ThreadParent):
	
	def __init__(self):
		ThreadParent.__init__(self)
		self.__dead = False
		self.log = []
		
	def run(self):
		print "StateMachine started"
		while not self.__dead:
			#~ print "reading state"
			self.log.append("x")
			sleep(1)
		
	def kill(self):
		print "aaagfh..."
		self.__dead = True
	
	def is_dead(self):
		return self.__dead
		
if __name__ == "__main__":
	sm = StateMachine()
	sm.start()
	while True and not sm.is_dead():
		sleep(3)
		m = raw_input("To end press 'q', else press return")
		if m.strip() == "q":
			sm.kill()
			print len(sm.log), "log messages"
			print sm.log
			exit(0)
		else:
			sm.log.append("mom")
			sleep(0.5)
